
from django_filters.rest_framework import FilterSet
from django_filters.filters import *
from apps.pbi.models import *
from apps.pbi.models import Pbi_Common_Pdfs, BusinessOpportunity, Contract, Order


class ClientFilter(FilterSet):
    """
    客户过滤
    """
    # add_time_begin=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加开始时间",lookup_expr="gte")
    # add_time_end=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加结束时间",lookup_expr="lte")
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    cooperation_methods = CharFilter(field_name="cooperation_methods", help_text="合作方式", lookup_expr="icontains")
    industry_types = CharFilter(field_name="industry_types", help_text="行业类型", lookup_expr="icontains")
    region_shi = CharFilter(field_name="region",help_text="区县_市",lookup_expr="icontains")
    region_xian = CharFilter(field_name="region",help_text="区县_县",lookup_expr="icontains")
    class Meta:
        model = Client
        fields = ['company','region_shi','region_xian', 'is_effective','add_time_begin','add_time_end',
                  'cooperation_methods',
                  'industry_types',
                  'client_property']


class ManufactorFilter(FilterSet):
    """
    厂家过滤
    """
    # add_time_begin=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加开始时间",lookup_expr="gte")
    # add_time_end=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加结束时间",lookup_expr="lte")
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    product_specialty = CharFilter(field_name="product_specialty", help_text="产品覆盖专业", lookup_expr="icontains")
    class Meta:
        model = SupplierManufactor
        fields = ['company','product_specialty', 'is_effective','add_time_begin','add_time_end']


class Pbi_Common_PdfsFilter(FilterSet):
    """
    Pbi公共pdf过滤
    """
    add_time_begin = DateFilter(field_name="create_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="create_time",help_text="结束创建时间",lookup_expr="lte")
    class Meta:
        model = Pbi_Common_Pdfs
        fields = ['type','add_time_begin','add_time_end','creator']

class ManufactorProductFilter(FilterSet):
    """
    厂家产品过滤
    """
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    product_specialty = CharFilter(field_name="product_specialty", help_text="产品覆盖专业", lookup_expr="icontains")
    class Meta:
        model = ManufactorProduct
        fields = ['company','product_specialty','add_time_begin','add_time_end']


class SupplierIntegratorFilter(FilterSet):
    """
    厂家过滤
    """
    # add_time_begin=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加开始时间",lookup_expr="gte")
    # add_time_end=rest_framework.DateTimeFilter(field_name="add_time",help_text="添加结束时间",lookup_expr="lte")
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    class Meta:
        model = SupplierIntegrator
        fields = ['company', 'introduce_method','is_effective','add_time_begin','add_time_end']



class BusinessOpportunityFilter(FilterSet):
    """
    商机管理过滤
    """
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    introduction_time_begin = DateFilter(field_name='introduction_time', lookup_expr='gte', label='开始日期')
    introduction_time_end = DateFilter(field_name='introduction_time', lookup_expr='lt', label='结束日期')
    #business_opportunity_stage
    business_opportunity_stage = CharFilter(field_name="business_opportunity_stage", help_text="商机阶段")

    class Meta:
        model = BusinessOpportunity
        fields = ['company', 'is_effective','add_time_begin','add_time_end','introduction_time_begin','introduction_time_end','business_opportunity_stage']


class ContractFilter(FilterSet):
    """
    合同管理过滤
    """
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    industry_type = CharFilter(field_name="business_opportunity__industry_type", help_text="行业类型")
    business_type = CharFilter(field_name="business_opportunity__business_type", help_text="业务类型")
    project_properties = CharFilter(field_name="business_opportunity__project_properties", help_text="项目属性")
    project_source = CharFilter(field_name="business_opportunity__project_source", help_text="项目来源")
    class Meta:
        model = Contract
        fields = ['company', 'is_effective','add_time_begin','add_time_end',
                  'industry_type',# 行业类型
                  'business_type',  # 业务类型
                    'project_properties',  # 项目属性
                    'project_source',  # 项目来源
                  ]


class OrderFilter(FilterSet):
    """
    订单管理过滤
    """
    add_time_begin = DateFilter(field_name='create_time', lookup_expr='gte', label='开始日期')
    add_time_end = DateFilter(field_name='create_time', lookup_expr='lt', label='结束日期')
    industry_type = CharFilter(field_name="contract__business_opportunity__industry_type", help_text="业务类型")
    business_type = CharFilter(field_name="business_type", help_text="专业分类")
    class Meta:
        model = Order
        fields = ['company', 'is_effective','add_time_begin','add_time_end',
                  'industry_type',# 行业类型
                  'business_type',  # 专业分类
                  ]

__all__ = [
    'ClientFilter',
    'ManufactorFilter',
    'SupplierIntegratorFilter',
    'ManufactorProductFilter',

]